//
//  ShoppingCarListCell.m
//  renmingongshe
//
//  Created by Mao on 2017/11/1.
//  Copyright © 2017年 xiaodian. All rights reserved.
//

#import "ShoppingCarListCell.h"

@implementation ShoppingCarListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.delBtn.hidden = YES;
}
- (IBAction)selectedClick:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    
    self.click(sender.selected);
    
}
- (IBAction)addOrsubGoods:(UIButton *)sender {
    NSInteger i = _editNum.text.integerValue;
    if (sender.tag) {
        //加
        _editNum.text = [NSString stringWithFormat:@"%ld",++i];
    }else
    {
        //减
        if (i==1) {
            return;
        }
        _editNum.text = [NSString stringWithFormat:@"%ld",--i];
    }
    self.addOrsubGoods(_editNum.text);
}

- (IBAction)delClick:(id)sender {
    self.delGoods();
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)cellConfigwithDic:(NSDictionary *)data
{
    self.selectedBtn.selected = self.choosed;
//    if (self.edited) {
//        self.selectedBtn.enabled = NO;
//    }else{
//        self.selectedBtn.enabled = YES;
//    }
    if (self.edited) {
        self.delBtn.hidden = NO;
        self.editView.hidden = NO;
        self.cartNum.hidden = YES;
        self.comView.hidden = YES;
        self.right.constant = 60;
    }else{
        self.delBtn.hidden = YES;
        self.editView.hidden = YES;
        self.cartNum.hidden = NO;
        self.comView.hidden = NO;
        self.right.constant = 10;
    }
    
    [_goodsIma sd_setImageWithURL:[NSURL URLWithString:[Utils getImaSting:data[@"goodsImg"]]] placeholderImage:[UIImage imageNamed:@"NoStore"] options:SDWebImageRetryFailed];
    _goodsName.text = data[@"goodsName"];

    _shopPrice.text = [NSString stringWithFormat:@"￥%.1f",![TXUtilsString isBlankString: data[@"shopPrice"]]?[data[@"shopPrice"]floatValue]:0.0];
    
    NSString *str;
    if (![TXUtilsString isBlankString:data[@"goodsSpec_pv"]]) {
        str = [NSString stringWithFormat:@"分润点 %.2f",[data[@"goodsSpec_pv"]floatValue]];
    }else{
        str = [NSString stringWithFormat:@"分润点 %.2f",[data[@"goods_pv"]floatValue]];
    }
    _pointNum.text = str;
    _cartNum.text = [NSString stringWithFormat:@"数量 %@",data[@"cartNum"]];
    _editNum.text = [NSString stringWithFormat:@"%@",data[@"cartNum"]];
    
    if ([data[@"specsName"]count]) {
        NSArray *arr = data[@"specsName"];
        NSMutableArray *a = [NSMutableArray array];
        
        for (NSDictionary *d in arr) {
            [a addObject:d[@"itemName"]];
        }
        _specName.text = [a componentsJoinedByString:@" "];
    }else{
        _specName.text = @"";
    }
}

@end
